//
//  JokesCollectionViewCell.m
//  SmileRead
//
//  Created by dllo on 15/8/22.
//  Copyright (c) 2015年 JIZ. All rights reserved.
//

#import "JokesCollectionViewCell.h"
#import "JokesModel.h"

@interface JokesCollectionViewCell ()

@property (nonatomic, retain) UITextView *textView;

@end

@implementation JokesCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.textView = [[UITextView alloc] initWithFrame:CGRectMake(10 * widthFit, 10 * heightFit, self.frame.size.width - 20 * widthFit, self.frame.size.height - 40 * heightFit)];
        self.textView.backgroundColor = [UIColor whiteColor];
        self.textView.font = [UIFont systemFontOfSize:19];
        [self.contentView addSubview:self.textView];
        self.textView.editable = NO;
        [_textView release];
    }
    return self;
}





- (void)setModel:(JokesModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
        self.textView.text = model.text;
    }
}


// 文本自适应

- (CGFloat)heightWithLabel:(UILabel *)label width:(CGFloat)width
{
    CGRect rect = [label.text boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]} context:nil];
    return rect.size.height;
}

- (void)dealloc
{
    [_textView release];
    [super dealloc];
}


@end
